package com.example.knowledgeget1.KnowtController;

import com.example.knowledgeget1.KnowtCommon.Entity.Study;
import com.example.knowledgeget1.KnowtCommon.Service.StudyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/studies")
public class StudyController {
    @Autowired
    private StudyService studyService;

    @PostMapping("/")
    public Study createStudy(@RequestBody Study study) {
        return studyService.createStudy(study);
    }

    @GetMapping("/")
    public List<Study> getAllStudies() {
        return studyService.getAllStudies();
    }

    @GetMapping("/{id}")
    public Study getStudyById(@PathVariable Long id) {
        return studyService.getStudyById(id);
    }

    @PutMapping("/{id}")
    public Study updateStudy(@PathVariable Long id, @RequestBody Study study) {
        return studyService.updateStudy(id, study);
    }

    @DeleteMapping("/{id}")
    public void deleteStudy(@PathVariable Long id) {
        studyService.deleteStudy(id);
    }
}